﻿@model  Authentication.Model.ViewModel.Account.GroupViewModel
<ul class="breadcrumb">
    <li>
        <i class="icon-home"></i>
        <a href="/">Account</a>
        <i class="icon-angle-right"></i>
    </li>
    <li>
        <i class="icon-lock"></i>
        <a href="#">Groups</a>
    </li>
</ul>
<!--/span-->

<div class="row-fluid">
    <div class="box span12">
        <div class="box-header" data-original-title>
            <h2><i class="halflings-icon lock"></i><span class="break"></span>Items</h2>
            <div class="box-icon">
                <a href="#" class="btn-minimize"><i class="halflings-icon chevron-up"></i></a>
            </div>
        </div>
        <div class="box-content">
            <div class="validation-summary alert alert-error">
                <a class="close" data-dismiss="alert">×</a>
                <h5 class="alert-heading">Reset validate</h5>
                @Html.AntiForgeryToken()
                @Html.ValidationSummary()
            </div>
            <table class="table table-striped bootstrap-datatable datatable" id="dataTables-1">
                <thead>
                    <tr>
                        <th class="text-left">Identifier</th>
                        <th class="text-left all">Group Name</th>
                        <th class="text-left">Description</th>
                        <th class="text-left all" style="width: 60px;">Action</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <div class="form-actions">
                @if (Model.IsSupperAdmin)
                {
                    <button id="btnNewGroup" class="btn btn-success btn-responsive">Add New Role</button>
                }
            </div>
        </div>
    </div>
    <!--/span-->
</div>
<!--/row-->
@*Check permission*@
@if (true)
{
    <div id="groupEditor" class="modal fade box brown">
        <div class="box-header">
            <h2><i class="halflings-icon white list"></i><span class="break"></span>Group Confirmation</h2>
            <div class="box-icon">
                <a data-dismiss="modal" class="close"><i class="halflings-icon white remove"></i></a>
            </div>
        </div>
        <div class="box-content">
            @using (Html.BeginForm("Groups", "Account", FormMethod.Post, new { @class = "form-horizontal", name = "Update", id = "Update" }))
            {
                <fieldset>
                    <div class="control-group">
                        @Html.LabelFor(m => m.GroupIdentifier, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.GroupIdentifier, new { @class = "span4" })
                            @Html.Hidden("btnClick")
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.GroupName, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextBoxFor(m => m.GroupName, new { @class = "span10" })
                        </div>
                    </div>
                    <div class="control-group">
                        @Html.LabelFor(m => m.Description, new { @class = "control-label" })
                        <div class="controls">
                            @Html.TextAreaFor(m => m.Description, new { @class = "span10" })
                        </div>
                    </div>
                    <div class="form-actions modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <input type="submit" name="btnUpdate" id="btnUpdate" class="btn btn-primary" value="Save changes" />
                    </div>
                </fieldset>
            }
        </div>
    </div>
}

@section scripts
{
    <script>
        $(document).ready(function () {
            var table = $('#dataTables-1').dataTable({
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                oLanguage: {
                    sProcessing: "<img src='http://www.arabianbusiness.com/skins/ab.main/gfx/loading_spinner.gif'/>"
                },
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 30,
                "sAjaxSource": '@Url.Action("GroupsData")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "bootstrap",//"full_numbers",
                "aoColumns": [
                            { "sName": "GroupIdentifier", "bSortable": false/*, "visible": false*/ },
                            { "sName": "GroupName", "bSortable": false },
                            { "sName": "Description", "bSortable": false },
                            { "sName": "CreateDate", "bSortable": false }],
                "aoColumnDefs": [{
                    "aTargets": [3],
                    "mData": null,
                    "mRender": function (data, type, full) {
                        return '<button class=\"btn btn-small btn-success\" onclick=\"showGroupEditor(\'' + full[0] + '\',\'' + full[1] + '\',\'' + full[2] + '\');\"><i class=\"halflings-icon white edit\"></i></button> <button class=\"btn btn-small btn-danger\" onclick=\"deleteGroup(\'' + full[0] + '\');\"><i class=\"halflings-icon white trash\"></i></button>';
                    }
                }]
            });
        });
    </script>
    @*Check permission*@
    @if (true)
    {
        <script type="text/javascript">
            function showGroupEditor(id, name, desc) {
                $('#btnClick').val(null);
                $('#GroupIdentifier').val(id);
                $('#GroupName').val(name);
                $('#Description').val(desc);
                $("#groupEditor").modal('show');

            }

            function deleteGroup(key, id) {
                ConfirmDlg('Confirm this data...!', 'Your data will be lost, are you really?', successFunction = function () {
                    $.post('@Authentication.Configuration.SystemConfiguration.DeleteGroupAction/', { code: key }, function (data) {
                        if (data.IsSuccess) reload();
                    });
                });
            }

            $("#btnNewGroup").click(function () {
                showGroupEditor(null, null, null);
                $('#btnClick').val('btnNewGroup');
            });
        </script>
    }
}
